package de.zainodis.authorlist.ui;

import de.zainodis.authorlist.R;
import de.zainodis.commons.utils.Toaster;
import android.app.ListFragment;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Base class for fragments that show lists and therefor need to occasionally
 * download data from the internet.
 * 
 * @author fzarrai
 * 
 */
public class ListDownloadBaseFragment extends ListFragment {

   /**
    * 
    * @param showMessage
    *           if true, a message will be displayed to the user in case there
    *           is no internet connection available.
    * @return true if an internet connection is available; false otherwise.
    */
   protected boolean internetAvailable(boolean showMessage) {
	 ConnectivityManager manager = (ConnectivityManager) getActivity().getSystemService(
		  Context.CONNECTIVITY_SERVICE);
	 NetworkInfo activeNetwork = manager.getActiveNetworkInfo();
	 boolean isAvailable = activeNetwork != null ? activeNetwork.isConnected() : false;

	 if (!isAvailable) {
	    Toaster.longToast(getString(R.string.internet_connection_required), getActivity());
	 }
	 return isAvailable;
   }
}
